Hello and welcome to this vigil on where to place javascript.
Could I have a script called can be placed either in my head section or in the body section of this
Tim old code.
Right so this is the hastier email could whitsun javascript from the previous video.
Right.
So you can place javascript either in the header section or any way in the body section.
So I'll tell you I will show you the effects of placing Javascript in the head and also the impact of
placing javascript on the body.
So we'll start with he has said come first so just copy these javascript removed that cut and pasted
into the code section and then save that to the javascript.
Now is in the head section of the TMI document so I'll save that if I run this.
Observe what would happen are lunch in Firefox.
Okay so if he can observe the javascript loads first.
It prevents any other part of the web page loading so windjammers script is placed in the header section.
It will load first before allowing any of the content to load.
So the only way you can get the content to display is by clicking the okay button.
So if I click or kick Be content when not display.
Okay that's the content for the web page.
So this is the effect of placing Javascript in the head section.
All right.
Next I'm gonna copy this same script and place it in the body section.
The best advice is to win place in Javascript in the body.
Body tag is best to place it just before the end.
Body tags will never be the last
item you place just before disclosing body tags.
Best place recommended took place for javascript because that way it doesn't prevent the page from load
it.
So if I saved that and run it are wanting Firefox all right he can see the pages look the last bartholdi
page content higher log jam a script and then this is a javascript and just click OK and the rest of
the page shows up.
So the advantage of placing javascript at the bottom just before the close in body tag is that it lets
the content on the page display without interfering with it whereas placing Javascript in the head section
prevents the content from loading and load sajjad script first.
In this video I give a demo on place in the javascript code in the head section of the hastier mail
document I saw in the body section of the hysteria document.
It's always best to place the javascript just before you close embody attack.
That way it lets your content load without interference.
I hope the video has been helpful.
Thank you so much for watching and bye for now.